<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.fc.util.*" %>
<%@ page import="com.fc.model.Coach" %>
<%@ page import = "com.fc.control.DateControl"%>
<%@ page import="com.fc.control.CoachControl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>coach</title>

		<script type="text/javascript" src="../../../js/jquery.js"></script>
		<link href="../../../css/info_teacher.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript">
	$(document).ready(function() {
		$('#formdiv').hide();
		$('[name=form_upload]').hide();
		$('#update_coach').hide();
		$('#upload_btn').click(function() {
		$('[name=form_upload]').slideToggle();
				});
		$('#add_coach').click(function() {
			$('#formdiv').slideToggle();
		});
		$('[name=edit]').click(function() {
		    $('#update_coachId').val($(this).prev().val());
		    $('#update_position').val($(this).parent().prev().prev().prev().prev().prev().text());
			$('#update_wages').val($(this).parent().prev().prev().text());
			$('#update_price').val($(this).parent().prev().prev().prev().text());
			$('#update_experience').val($(this).parent().prev().text());
			$('#update_coach').fadeIn();
		});
		$('#cancel').click(function() {
			$('#update_coach').fadeOut();
		})
			$('#submit_btn').click(function() {
			$.ajax( {
				type : "get",
				cache : false,
				url : "coach_add.jsp",
				dataType : "json",
				data : {
					store_id : $('#new_store_id').val(),
					addtime : $('#new_addtime').val(),
					wages : $('#new_wages').val(),
					type : $('#new_type').val(),
					experience : $('#new_experience').val(),
					position : $('#new_position').val(),
					price : $('#new_price').val(),
					
					idcard : $('#new_idcard').val(),
					name : $('#new_name').val(),
				},
				success : function(data) {
					if (data.status == 1) {
						window.location.reload();
					} else {
						alert("插入失败！");
					}
				}
			});
		})
		$('#update_btn').click(function() {
			$.ajax( {
				type : "get",
				cache : false,
				url : "coach_update.jsp",
				dataType : "json",
				data : {
					position : $('#update_position').val(),
					wages : $('#update_wages').val(),
					price : $('#update_price').val(),
					experience : $('#update_experience').val(),
					coachId : $('#update_coachId').val()
				},
				success : function(data) {
					if (data.status == 1) {
						window.location.reload();
					} else {
						alert("修改失败！");
					}
				}
			});
		})
				$('[name=delete]').click(function() {
					var isConfirm = confirm("确认删除？");
					if (isConfirm == true) {
						$.ajax( {
							type : "get",
							cache : false,
							url : "coach_delete_do.jsp",
							dataType : "json",
							data : {
								coachId : $(this).prev().prev().val()
							},
							success : function(data) {
								if (data.status == 1) {
									window.location.reload();
								} else {
									alert("删除失败！");
						}
					}
				});
			}
		})
	
	})
</script>
</head>
<body>
      <div class="main">
<form>
<strong>教练列表</strong>
   <table>
   <thead>
   <tr>

   	<th width="150">姓名</th>
   	<th width="200">职位</th> 
   	<th width="200">类型</th> 	
   	<th width="200">价格/小时</th> 
   	<th width="100">工资</th>
   	<th width="150">执教时间</th>		
   	<th width="150">操作</th>
   </tr>
</thead>
<tbody>
<%
	request.setCharacterEncoding("UTF-8");
	int pages = ParamUtil.getInt(request, "pages", 0);
	int rowsPerPage = ParamUtil.getInt(request, "pageSize", 10);
	DateControl dc = new DateControl();
	String addtime1 = dc.Date();
	CoachControl cc = new CoachControl();
	Coach coach = new Coach();

	List<Coach> list = new ArrayList<Coach>();
	list = (List) cc.getCoach(pages,rowsPerPage); 
	      
	for (int i = 0; i < list.size(); i++) {
		coach = list.get(i);
%>  
	
		<tr>
		<td align="center"><%=coach.getName()%></td>
		<td align="center"><%=coach.getPosition()%></td>
		<td align="center"><%=coach.getType()%></td>
		<td align="center"><%=coach.getPrice()%></td>
	    <td align="center"><%=coach.getWages()%></td>
		<td align="center"><%=coach.getExperience()%></td>
		<td align="center">
								<input type="hidden" value="<%=coach.getId()%>">
								<input type="button" value="编辑" name="edit">
								<input type="button" value="删除" name="delete">
							</td>
		</tr>
	<%
		}
	%>   	
   	</tbody>
   </table>
   <center><input type="button" id="add_coach" value="添加教师" /></center>
			</form>
			
		<div id="formdiv">
			<form action="#" method="post">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
						<td>
							店铺编号：
							<input type="text" id="new_store_id" name="new_store_id" value="" />
						</td>
						<td>
							入职时间：
							<input type="text" id="new_addtime" name="new_addtime" value="<%=addtime1%>" />
						</td>
						<td>
							工资(元)：
							<input type="text" id="new_wages" name="wages" value="" />
						</td>
						<td>
							类型：
							<select name="type" id="new_type">
							<option value="普通教练" selected>普通教练</option>
							<option value="私人教练">私人教练</option>
							</select>
						</td>
						</tr>
						<tr>		
						<td>
							执教时间（年）：
							<input type="text" id="new_experience" name="experience" value="" />
						</td>		
						<td>
							职位：
							<input type="text" id="new_position" name="position" value="" />
						</td>		
						<td>
							价格(元)：
							<input type="text" id="new_price" name="price" value="" />
						</td>		
						<td>
							身份证号：
							<input type="text" id="new_idcard" name="idcard" value="" />
						</td>
						</tr>
						<tr>		
						<td>
							姓名：
							<input type="text" id="new_name" name="name" value="" />
						</td>																												
						<td>
							<input type="button" id="submit_btn" value="提交" />
						</td>
					</tr>
				</table>
			</form>
		</div>
			
			<div id="update_coach">
				职位：
				<input type="text" id="update_position" />
				工资(元)：
				<input type="text" id="update_wages" />
				价格/小时：
				<input type="text" id="update_price" />
				执教时间(年):
				<input type="text" id="update_experience" />
				<input type="hidden" id="update_coachId" />
				<center><input type="button" id="update_btn" value="修改" />　
				<input type="button" id="cancel" value="取消"></center>
			</div>
		</div>
</body>
</html>